//
//  GOBall.m
//  BetterPong
//
//  Created by Samuel Goodwin on 2/21/07.
//

#import "GOBall.h"


@implementation GOBall

//Geometry
- (int)radius
{
	return radius;
}

- (void)setRadius:(int)aRadius
{
	radius = aRadius;
}

- (NSPoint)center
{
	NSRect box = [[self shape] bounds];
	NSPoint pos = NSMakePoint(box.origin.x + (box.size.width/2), box.origin.y + (box.size.height/2));
	return pos;
}
//Collision
- (BOOL)collides_with:(GOSprite *)target
{
	int dx = abs(center.x - [target center].x);
	int dy = abs(center.y - [target center].y);
	return dy*dy+dx*dx <= radius*radius;
}


//Inits
- (id)initWithPosition:(NSPoint)aPoint
{
	[super initWithPosition:aPoint];
	radius = 5;
	NSPoint position = aPoint;
	double distance = 2*sqrt((radius*radius)+(radius*radius));
	NSRect aRect = NSMakeRect((position.x -distance),(position.y -distance),radius*2,radius*2);
	shape = [[NSBezierPath bezierPathWithOvalInRect:aRect] retain];
	
	return self;
}

- (id)init
{
	[super initWithPosition:NSMakePoint(0.0,0.0)];
	radius = 5;
	double distance = 2*sqrt((radius*radius)+(radius*radius));
	NSRect aRect = NSMakeRect((center.x -distance),(center.y -distance),radius*2,radius*2);
	shape = [[NSBezierPath bezierPathWithOvalInRect:aRect] retain];
	return self;
}
@end
